/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.City;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value = "cityconverter")
public class CityConverter implements Converter{
    
     @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        City city = new City();
        if(! value.equals("null"))
         city.setId((Long.valueOf(value)));
        return city ;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        City city = (City) value;
        return "" + city.getId();
    }
    
}
